<html lang="en">
<head>
    <meta charset="UTF-8">

</head>
<script type="text/javascript">
    var socket;

    if(window.WebSocket){
        socket= new WebSocket("ws://localhost:8888/ws");
        socket.onmessage=function(ev){
            var  ta= document.getElementById("responseText");
            ta.value=ta.value+"\n"+ev.data;

        }
        socket.onOpen=function(ev){ var  ta= document.getElementById("responseText");
            ta.value="连接开启";
            send("AUTH 123456")
        }
        socket.onclose= function(ev){ var  ta= document.getElementById("responseText");
            ta.value="连接关闭";
        }

    }else{
        alert("浏览器不支持webSocket")
    }
    function send(message) {
        if (!window.WebSocket){
            return ;
        }
        if (socket.readyState==WebSocket.OPEN){
            socket.send(message);
        }else{
            alert("连接未开启");
        }

    }
    function clearMsg() {
        var  ta= document.getElementById("responseText");
        ta.value = "";
    }
    function connection() {
        socket =null;
        socket= new WebSocket("ws://localhost:8888/ws");
    }

</script>
<body>

<form onsubmit="return false;">
    <textarea name="message" style="width: 400px;height: 200px;">SET key value</textarea>
    <input type="button" value="发消息" onclick="send(this.form.message.value)">
    <input type="button" value="重新连接" onclick="connection()">
    <h3>服务器输出：</h3>
    <textarea id="responseText"  style="width: 400px;height: 200px;"></textarea>

    <input type="button" value="清空消息" onclick="clearMsg()">

</form>


</body>

<script >




</script>
</html>